/*
 *  Copyright 2015-2016, RenGu Technology (BeiJing) Co., Ltd.
 *  All right reserved.
 *
 *  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF RENGU TECHNOLOGY (BeiJing) CO., LTD.
 *
 *  THE CONTENTS OF THIS FILE MAY NOT BE DISCLOSED TO THIR PARTIES,
 *  COPIED OR DUPLICATED IN ANY FORM, IN WHOLE OR IN PART,
 *  WITHOUT THE PRIOR WRITTEN PERMISSION OF RENGU TECHNOLOGY (BeiJing) CO., LTD.
 *
 *  DbCommon
 *
 *  Edit History:
 *      lizhangtao Created on 2020年04月10日
 *
 */
package cc.rengu.igas.acct.common.dao;

import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.base.StringUtil;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * 数据库操作公共
 *
 * @author lizhangtao
 */
public class MapperCommon {

    public static String dbPoolName;
    public RgLogger rglog = RgLog.getLogger(this.getClass().getName());

    public void extractDbPoolName() throws Exception {
        if (StringUtil.isNullorEmpty(dbPoolName)) {
            XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.ACCT_POOL_NAME);
            String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
            if (null != corporation && !corporation.isEmpty()) {
                String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
                dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.ACCT_POOL_NAME);
            }
        }
        if (StringUtil.isNullorEmpty(dbPoolName)) {
            throw new Exception("获取数据库连接池名称失败!");
        }
    }

    public static String getDbPoolName() throws Exception {
        if (StringUtil.isNullorEmpty(dbPoolName)) {
            new MapperCommon().extractDbPoolName();
        }
        return dbPoolName;
    }
}
